/*! oauthapp.rank 1.9.8 */
(function () {
    "use strict";

    var server = oauthapp.settings.server + '/api/AppRank';

    var appid = oauthapp.settings.appid;

    var bearerToken = "Bearer " + oauthapp.settings.access_token;

    // 榜单集合
    oauthapp.ranks = function () {
        return $.ajax({
            url: server + "/" + appid + "/Report",
            method: "GET",
            headers: {
                "Content-Type": "application/json",
                'Authorization': bearerToken
            }
        });
    }

    // 单个榜单
    oauthapp.rank = function (rankKey, platform, take) {
        var params = [
            "platform=" + platform,
            "take=" + (take || 30)
        ];

        return $.ajax({
            url: server + "/" + appid + "/" + rankKey + "?" + params.join('&'),
            method: "GET",
            headers: {
                "Content-Type": "application/json",
                'Authorization': bearerToken
            }
        });
    }

    // 我的排行
    oauthapp.rankOfMe = function (rankKey, platform, unionid) {

        var params = [
            "platform=" + platform,
            "unionid=" + unionid
        ];

        return $.ajax({
            url: server + "/" + appid + "/" + rankKey + "/Me?" + params.join('&'),
            method: "GET",
            headers: {
                "Content-Type": "application/json",
                'Authorization': bearerToken
            }
        });
    }

    // 提交分数
    oauthapp.rankSubmit = function (rankKey, data) {
        return $.ajax({
            url: server + "/" + appid + "/" + rankKey,
            method: "PUT",
            headers: {
                "Content-Type": "application/json",
                'Authorization': bearerToken
            },
            data: JSON.stringify(data)
        });
    }

})();